package com.future.hair.server.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.future.hair.server.config.jjwt.JwtHelper;
import com.future.hair.server.config.result.CommonResult;
import com.future.hair.server.entity.BarberAppraise;
import com.future.hair.server.mapper.BarberAppraiseMapper;
import com.future.hair.server.model.PageModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;



/**
*
* @author future-RogueYBJ
* @since 2020-05-23
* @version v1.0
*/

@RestController
@RequestMapping("//hair/barberAppraise")
@Api(tags = "BarberAppraise管理接口")

public class BarberAppraiseController{
    @Autowired
    private BarberAppraiseMapper mapper;

    @Autowired
    private RedisTemplate<String,String> redisTemplate;

    @ApiOperation(value = "查询 BarberAppraise 列表")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public CommonResult<List<BarberAppraise>> barberAppraiseList(@RequestBody PageModel data,@RequestHeader String token) {
        return CommonResult.data(mapper.selectPage(new Page<>(data.getSize() , data.getCurrent()), null).getRecords());
    }

    @ApiOperation(value = "查询当前 BarberAppraise")
    @RequestMapping(value = "/id", method = RequestMethod.POST)
    public CommonResult<BarberAppraise> barberAppraiseId(@RequestBody BarberAppraise data,@RequestHeader String token) {
        return CommonResult.data(mapper.selectById(data.getId()));
    }

    @ApiOperation(value = "增加 BarberAppraise")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public CommonResult<Integer> create(@RequestBody BarberAppraise data,@RequestHeader String token) {
        if (null==data.getBarberId()||null==data.getType()){
            return CommonResult.failed("字段不能为空");
        }
        data.setCreateTime(null);
        data.setUpdataTime(null);
        data.setUserId(JwtHelper.getByUserId(token));
        Integer result = mapper.insert(data);
        if (result == 1){
            return CommonResult.data(result);
        }else {
            return CommonResult.failed("创建失败");
        }
    }

    @ApiOperation(value = "更新 BarberAppraise")
    @RequestMapping(value = "/upData", method = RequestMethod.POST)
    public CommonResult<Integer> upData(@RequestBody BarberAppraise data, @RequestHeader String token) {
        Integer result = mapper.updateById(data);
        if (result==1){
            return CommonResult.data(result);
        }else {
            return CommonResult.failed("更新失败");
        }
    }

    @ApiOperation(value = "删除 BarberAppraise")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public CommonResult<Integer> delete(@RequestBody BarberAppraise data,@RequestHeader String token) {
        Integer result = mapper.deleteById(data.getId());
        if (result==1){
            return CommonResult.data(result);
        }else {
            return CommonResult.failed("删除失败");
        }
    }
}